<html>
	<head>
		<title>finacial.html</title>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<link href="../../css/general1.css" rel="stylesheet" type="text/css" />
		<link href="style/css.css" rel="stylesheet" type="text/css" />
		<link href="../../zephyr/css/drift.css" rel="stylesheet"
			type="text/css" />
		<script type="text/javascript" src="../../script/hiawardbpm.js"></script>
		<script type="text/javascript" src="../../script/prototype.js"></script>
		<script type="text/javascript" src="/vchzms-hiaward/dwr/engine.js"> </script>
		<script type="text/javascript" src="/vchzms-hiaward/dwr/util.js"> </script>
		<script type="text/javascript"
			src="/vchzms-hiaward/dwr/interface/OutService.js"></script>
		<script type="text/javascript"
			src="/vchzms-hiaward/dwr/interface/Dao.js"></script>
	    <script type="text/javascript"
			src="/vchzms-hiaward/dwr/interface/OperatePbcFileDwrAction.js"></script>
		<script type="text/javascript"
			src="/vchzms-hiaward/dwr/interface/SetKeyAndValueDwrAction.js"></script>
		<script type="text/javascript">
		 var subno;
		 var exchno;
		 var subMsg;
         var voucherid
         var mergeAccno;
         var mergeVchno;
         var mergeAmount;
         var acctype="2";
         var mergeBrbank;
		 var subFlag=false;
		 var mergeres=true;
		 var financialFlag=false;
		 function eh(msg) { 
          alert(msg); 
       } 
        function subForm(){
         alert("sub....");
          var webData=buildWebData(subMsg);
          var xmlMsg=window.dialogArguments;
          //alert(xmlMsg.getXmlDocument().xml);
          xmlMsg.setCommand(12);
          xmlMsg.setWebData(webData);
          xmlMsg.buildXML();
          var url="/vchzms-hiaward/ProcessAjaxHandler";
          alert(xmlMsg.getXmlDocument().xml);
          new Ajax.Request(url,{
          method:'post',
          postBody:xmlMsg.getXmlDocument().xml,
          contentType:'application/x-www-form-urlencoded',
          encoding:'UTF-8',
          onComplete:function(transport){
	          try{
		          if(200==transport.status){
		               window.close();
		              }
		          if(400==transport.status){
		              }
	          }catch(err){
	              alert('js异常');
	          }
          }
       });
         }
         function buildWebData(msg){
         var xmlMsg=window.dialogArguments;
          var webData=new WebData();
          var vchsid=xmlMsg.getWebData().getProperty('vchsid');
          var accno=document.getElementById("accno").value;
          var amount=document.getElementById("amount").value;
          var vchno=document.getElementById("vchno").value;
          var batno=document.getElementById("batno").value;
          var vchtype=document.getElementById("vchtype").value;
          var vchdate=document.getElementById("vchdate").value;
          var vchpwd=document.getElementById("vchpwd").value;
          var finaid=$('finaid').value;
          var signtype=$('signtype').value;
          var paymodes=$('paymode').options;
          for(var i=0;i<paymodes.length;i++){
             if(paymodes[i].selected){
                webData.setProperty('paymode',paymodes[i].value);
             }
          }
          var ifamounts=$('ifamount').options;
          for(var i=0;i<ifamounts.length;i++){
               if(ifamounts[i].selected){
                 webData.setProperty('ifamount',ifamounts[i].value);
               }
          }
          var payinst=$('payinst').value;
          var payvchno=$('payvchno').value;
          var vchchar=$('vchchar').value;
          var payamount=$('amount').value;
          getMerged();
          if(msg=='3'){
            var editselect=document.getElementById("editselect").value;
            alert(editselect);
            webData.setProperty('rtreason',editselect);
          }
          webData.setProperty('finaid',finaid);
          webData.setProperty('signtype',signtype);
          webData.setProperty('vchchar',finaid);
          webData.setProperty('payamount',signtype);
          webData.setProperty('payvchno',payvchno);
          webData.setProperty('payinst',payinst);
          webData.setProperty('payvchno',payvchno);
          webData.setProperty('accno',accno);
          webData.setProperty('amount',amount);
          webData.setProperty('acctype',acctype);
          webData.setProperty('vchno',vchno);
          webData.setProperty('vchtype',vchtype);
          webData.setProperty('vchdate',vchdate);
          webData.setProperty('vchpwd',vchpwd);
          webData.setProperty('vchsidInput',vchsid);
          webData.setProperty('batno',batno);
          alert(msg+"---->--->---->");
          webData.setProperty('chkres',msg);
          webData.setProperty('chkstate','3');
          return webData;
         }
         //获得客户信息 
         function getCustInfo(){
          var accno=$('accno').value;
          //var acc="aaa";
          //alert(acc);
            DWREngine.setErrorHandler(eh);
            OutService.Z_BAPI_ACCOUNT_INFO(accno,function(data){
              var custid=data.custId;
              alert(custid);
             document.getElementById("coName").innerHTML=data.accName;
               $('receive').value=data.accName;
               alert(data.accName);
              OutService.Z_BAPI_BP_GET_ORG_DETAIL(0001,function(data1){
                $('connector').innerHTML=data1.connector;
               $('tel').innerHTML=data1.tel;
              });
           });
           isNormalAcc(accno);
         }
         //获得票据信息
         function getVoucherInfo(){
          var xmlMsg=window.dialogArguments;
	     var vchsid=xmlMsg.getWebData().getProperty('vchsid');
	     voucherid=vchsid;
         Dao.getVoucherById(vchsid,function(data){
          $('accno').value=data.accno;
          $('vchno').value=data.vchno;
          $('amount').value=data.amount;
          $('vchtype').value=data.vchtype;
          $('vchpwd').value=data.vchpwd;
          $('vchdate').value=data.vchdate;
          $('finaid').value=data.finaid;
          $('signtype').value=data.signtype;
           if(data.checkreason!=null){
             alert("复核不通过票据");
              $('checkreason').innerHTML="<table class='tablist1' width='100%'><tr><td width='35%'>复核不通过理由</td><td>"+data.checkreason+"</td</tr></table>";
          }
           if(data.rereason!=null){
             alert("记账返回票据");
              $('checkreason').innerHTML="<table class='tablist1' width='100%'><tr><td width='35%'>返回经办理由</td><td>"+data.rereason+"</td</tr></table>";
          }
          subno=data.subno;
          exchno=data.exchno;
          mergeAccno=data.accno;
          mergeAmount=data.amount;
          mergeVchno=data.vchno;
          mergeVsbank=data.vsbank;
          var acc=data.accno;
          isNormalAcc(acc);
           getCustInfo();
            });
         }
         //判断是否是普通账户
         function isNormalAcc(accno){
           alert(accno);
           OutService.Z_BAPI_BP_SIGN_PROD_GETDETAIL(accno,function(data){
           alert(data);
            if(data==1){
              alert("非财政户");
              acctype=1;
               $('finainfo').style.display='none';
            }else{
              acctype=2;
               $('finainfo').style.display='block';
              //getVoucherInfo();           
            }
          });
         }
         //勾兑的具体实现
         function merge(msg){
          subMsg=msg;
          var vchsession;
          var vchdate;
          var obj=new Object();
          obj.subno=subno;
          SetKeyAndValueDwrAction.getConfigDataByProperties(obj,function(data){
           for(var i=0;i<data.length;i++){
            if(data[i].key=="VCHZMS_PBC_SESSION"){
              vchsession=data[i].value;
            }
            if(data[i].value=="VCHZMS_PBCDATA_DATE"){
              vchdate=data[i].value; 
            }
           }
          });
          var amount=$('amount').value;
          var obj=new Object();
          obj.state=1;
          obj.amount=amount;
          if(exchno!=null){
           obj.exchno=exchno;
          }
          obj.vchsession=vchsession;
          obj.vchdate=vchdate;
          OperatePbcFileDwrAction.getPbcDataByProperties(obj,function(data){
          if(data!=null){
            if(data.length==1){
               pbcsid=data[0].pbcsid;
               var xmlMsg=window.dialogArguments;
               var vchsid=xmlMsg.getWebData().getProperty('vchsid');
               alert(vchsid+"---");
               OperatePbcFileDwrAction.merge(vchsid,pbcsid,function(data){
                  alert("勾兑成功");
                  subForm();
               });
            }
            if(data.length>1){
               alert("很多匹配项哦"+data.length);
               mergeres=true;
               openwin();
                var vchtab="<table class='tablist1'><tr><td colspan='4' class='title2'>票面数据</td></tr><tr><td>帐号</td><td>凭证号</td><td>金额</td><td>提出行号</td></tr><tr><td>"+mergeAccno+"</td><td>"+mergeVchno+"</td><td>"+mergeAmount+"</td><td>"+mergeVsbank+"</td></tr></table>";
                $('vch').innerHTML=vchtab;
                var pbctab="<table class='tablist1'><tr><td colspan='5' class='title2'>人行数据</td></tr><tr><td>选择</td><td>帐号</td><td>凭证号</td><td>金额</td><td>提出行号</td></tr>";
                
               for(var i=0;i<data.length;i++){
                  pbctab+="<tr><td><input type='radio' name='merged' value='"+data[i].pbcsid+"'></td><td>"+data[i].accno+"</td><td>"+data[i].vchno+"</td><td>"+data[i].amount+"</td><td>"+data[i].vsbank+"</td></tr>";
               }
               pbctab+="</table>";
               $('pbc').innerHTML=pbctab;
               subFlag=true;
            }
          }
          if(data==null||data.length==0){
            openwin();
            mergeres=false;
            var vchtab="<table class='tablist1'><tr><td colspan='4' class='title2'>票面数据</td></tr><tr><td>帐号</td><td>凭证号</td><td>金额</td><td>提入行号</td></tr><tr><td>"+mergeAccno+"</td><td>"+mergeVchno+"</td><td>"+mergeAmount+"</td><td>"+mergeVsbank+"</td></tr></table>";
            //var pbctab="<table class='tablist1'><tr><td colspan='4' class='title2'>人行数据</td></tr><tr><td>帐号</td><td>凭证号</td><td>金额</td><td>提入行号</td></tr><tr><td colspan='4'>无匹配项</td></tr></table>";
            $('vch').innerHTML=vchtab;
            //$('pbc').innerHTML=pbctab;
            alert("无可匹配项");
           }
          });
         }
         //进行勾兑的方法
          function getMerged(){
          if(subFlag){
           var mergedArr=document.getElementsByName("merged");
           for(var i=0;i<mergedArr.length;i++){
             if(mergedArr[i].checked==true){
               var mergedValue=mergedArr[i].value;
               OperatePbcFileDwrAction.merge(voucherid,mergedValue,function(data){
                  alert("勾兑成功");
               });
             }
           }
          }
         }
         //隐藏遮蔽层的方法
         function closeWin(){
         document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none';
         }
         //显示退票理由的遮蔽层
         function retRes(){
          alert('退票');
          changeReres();
          document.getElementById('rlight').style.display='block';
		  document.getElementById('fade').style.display='block';
         
         }
          //编辑修改退票理由的方法
          function changeReres(){
           var retArrs=$('rtRes').options;
           alert(retArrs.length);
           for(var i=0;i<retArrs.length;i++){
             if(retArrs[i].selected==true){
              $('editselect').value=retArrs[i].value;
              }
           }
         }
         //根据勾兑的结果判断是提交还是不提交直接关闭遮蔽层
         function subornot(){
          if(mergeres){
            subForm();
          }
           closeWin();
         }
          //提交的方法 可以判断该数据是否进行了勾兑
         function totalSub(msg){
            if(pbcsid==null){
              merge(msg)
            }else{
              subForm();
            }
         }
    </script>
	</head>
	<body leftmargin="0" topmargin="0">
		<center>
			<table width="900" border="1" cellspacing="0" cellpadding="0">
				<tr>
					<td width="65%" height="80">
						<table width="100%" border="1" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<img src="pic/00000001.jpg" width="601" height="283"/>
								</td>
							</tr>
							<tr>
								<td>
									<img src="pic/00000002.jpg" width="601" height="283" />
								</td>
							</tr>
						</table>
					</td>
					<td width="35%" height="" valign="top">
						<span style="width: 28%" class="title1"> <a name="tag"
							class="selectli1">客户信息</a> </span>
				<table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="tablist1">

							<tr>
								<td width="35%">
                                      公司名称:
								</td>
								<td>
									<span id="coName"></span>
								</td>
							</tr>
							<tr>
								<td>
								  联系人:
								</td>
								<td>
									<span id="connector"></span>
								</td>
							</tr>
							<tr>
								<td>
								 联系电话:
								</td>
								<td>
									<span id="tel"></span>
								</td>
							</tr>
							<tr>
								<td>
								 备注:
								</td>
								<td>
									<span id="remark"></span>
								</td>
							</tr>
						</table>
						<span id="finainfo">
						<span style="width: 39%" class="title1"> <a name="tag"
							class="selectli1">支付指令信息</a></span>	
				        <table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="tablist1">

							<tr>
								<td width="35%">
                                      财局编码:
								</td>
								<td>
									<span id="">
									<input id="finaid" type="text" value="">
									</span>
								</td>
							</tr>
							<tr>
								<td>
								  签约帐户类型:
								</td>
								<td>
									<span id="">
									  <input id="signtype" type="text"/>
									</span>
								</td>
							</tr>
							<tr>
							 <!-- 根据财局编码，显示可选择的支付方式 -->
								<td>
								 支付方式:
								</td>
								<td>
									<span id="">
									 <select id="paymode">
									  <option value='0'>授权支付</option>
									  <option value='1'>直接支付</option>
									 </select>
									</span>
								</td>
							</tr>
							<!-- <tr>后台需要填充
								<td>
								 支付类型:
								</td>
								<td>
									<span id="">支付</span>
								</td>
							</tr> -->
							<tr>
								<td width="35%">
								<!-- 如果签约账户类型为零余额合并账户 才显示此项 -->
                                      是否使用额度支付:
								</td>
								<td>
									<span id="">
									  <select id="ifamount">
									   <option value='0'>是</option>
									   <option value='1'>否</option>
									  </select>
									</span>
								</td>
							</tr>
							<tr>
								<td>
								  支付指令编号:
								</td>
								<td>
								    <!-- 1、	支付方式为授权支付，且财局编码为北京、海淀、石家庄、上海时出现此字段
2、	支付方式为直接支付、且财局编码为北京、海淀时出现此字段 -->
									<span id="">
									 <input id="payinst" type='text'/>
									</span>
								</td>
							</tr>
							<tr>
							 <!-- 财局编码为北京、海淀时出现此字段 -->
								<td>
								 付款凭证号:
								</td>
								<td>
									<span id=""><input type="text" id="payvchno"/></span>
								</td>
							</tr>
							<tr>
							<!-- 支付方式为直接支付，且财局编码为广州时出现此字段 -->
								<td>
								 凭证字号:
								</td>
								<td>
									<span id=""><input type="text" id="vchchar"/></span>
								</td>
							</tr>
							<tr>
								<td>
								金额:
								</td>
								<td>
									<input name="amount" type="text" value="123444" id="amount" />
								</td>
							</tr>
						</table>
						</span>
						<span style="width: 28%" class="title1"><a name="tag"
							class="selectli1">票据信息</a></span>
						<table width="100%" border="0" cellpadding="0" cellspacing="0"
							class="tablist1">
							<tr>
								<td width="35%">
								 帐号:
								</td>
								<td width="76%">
									<input id="accno" name="accno" type="text" value="1111" onchange="getCustInfo()"/>
								</td>
							</tr>
							<tr>
								<td width="35%">
								收款人名称:
								</td>
								<td width="76%">
									<input id="receive" name="receive" type="text" />
								</td>
							</tr>
							<tr>
							   <td colspan="2">
							  <table>
							  <tr>
								<td>
								  凭证类型:
								</td>
								<td>
									<input id="vchtype" type="text"   maxlength="1" size="1"/>
								</td>
							    <td>批次号:</td>
								<td>
								<input id="batno" type="text"   maxlength="1" size="1"/>
								</td>
								</tr>
								</table>
								</td>
							</tr>
							   
							<tr>
							    <td>凭证号:</td>
								<td>
									<input id="vchno"  type="text"  maxlength="1" size="1" />
								</td>
							</tr>
							
							<tr>
								<td>
								凭证日期:
								</td>
								<td>
									<input name="vchdate" type="text"  id="vchdate" />
								</td>
							</tr>
							
							<tr>
								<td>
								密码:
								</td>
								<td>
									<input name="vchpwd" type="text"  id="vchpwd" />
								</td>
							</tr>
							
							<tr>
								<td>
								密码结果:  
								</td>
								<td>
                                 <span id="pswdres" >通过</span>
								</td>
							</tr>
						</table>
						<span id="checkreason">
						
						</span>
						<span id="rereason">
						
						</span>
					</td>
				</tr>
			</table>
			<table width="40%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center" valign="bottom">

						<label>
							<input type="button" name="Submit" id="sub1" value="审票通过"
								class="btn1" onclick="totalSub('2')" />
						</label>
						<label>
							<input type="button" name="Submit" value="审票不通过" class="btn1"
								onclick="retRes()" />
						</label>
						<label>
							<input type="button" name="Submit2" value="手工处理" class="btn1"
								onclick="totalSub('4')" />
						</label>
						<label>
							<input type="button" name="Submit2" value="下一条" class="btn1" />
						</label>
						<input type="button" name="Submit3" value="关闭" class="btn1"
							onClick="totalSub()" />
					</td>
				</tr>
			</table>
			<script type="text/javascript">
              getVoucherInfo();
            </script>
			<!-- 遮蔽层 显示可勾兑的信息 -->
			<div id="light" class="white_content_audit">
			<table align="center" width="600px" height="150px" border="0"
				class="tablist1">
				<tr>
					<td width="300px">
						<span id="vch"></span>
						</td>
					<td width="300px">
						<span id="pbc"> </span>
					</td>
				</tr>
			</table>
			
			<p align="center">
				<a href="javascript:void(0)" onclick="subornot()"> 确定 </a>
			</p>
			<p align="center">
				<a href="javascript:void(0)" onclick="showimge()"> 票据图</a>
			</p>
		</div>
		<!-- 遮蔽层 显示退票理由 -->
		<div id="rlight" class="white_content_audit">
			<table align="center" width="600px" height="150px" border="0"
				class="tablist1">
				<tr>
					<td width="300px">
					  <select id="rtRes">
					     <option>111</option>
					     <option>222</option>
					     <option>333</option>
					  </select>
					  <button class='btn1' onclick="changeReres()">编辑所选项</button>
					</td>
					<td width="300px">
					   <textarea rows="2" cols="30" id="editselect"></textarea>
					</td>
				</tr>
			</table>
			
			<p align="center">
				<a href="javascript:void(0)" onclick="totalSub('3')"> 确定 </a>
			</p>
		</div>
		<!-- 在遮蔽层上显示的图片 用于在勾兑的时候查看图片信息 -->
		<div id="showimg" class="img_audit">
		              <table width="100%" border="1" cellspacing="0" cellpadding="0">
							<tr>
								<td>
									<span><img src="pic/00000001.jpg" id="fimage"
											width="601" height="283" onclick="closeimg()" /> </span>
								</td>
							</tr>
							<tr>
								<td width="601" height="283">
									<span><img src="pic/00000002.jpg" id="bimage"
											width="601" height="283" onclick="closeimg()" /> </span>
								</td>
							</tr>
						</table>
		</div>
		<div id="fade" class="black_overlay"></div>
		
		<script type="text/javascript">
		  function openwin() {
		//var ticket_frame = document.getElementById("ticket_cont").documentElement;
		//var img = el.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src;
		//addCookie("img_src",img,-1);
		//document.ticket.src=img;
		//alert($("content_frame").$("ticket").innerHTML);
		document.getElementById('rlight').style.display='none';
		document.getElementById('light').style.display='block';
		document.getElementById('fade').style.display='block';
		//ticket_frame.contentWindow.document.getElementById('ticket').src = img;
		//alert(ticket_frame);
		//setTimeout(function(){ticket_frame.contentWindow.document.getElementById('ticket').src = img;},3000);
		//document.getElementById('ticket_cont').contentWindow.document.getElementById('ticket').src = img;
		
	     }
		</script>
		</center>
	</body>
</html>


